﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AddIn.EA.Architecture.ComponentLogic.ElementModel;

namespace AddIn.EA.Architecture.ComponentLogic.StandardProject.Builders.Process
{
    public class ElementBuilderProcessImplementation : ElementBuilder
    {
        public override void BuildStructure(AddIn.EA.Architecture.ComponentLogic.ElementModel.Package viewModel, AddIn.EA.Framework.RepositoryManager templateRepository, BusinessEntityStandardProject itemEntity)
        {
            BuildProcessImplementationElement(viewModel, templateRepository, itemEntity);
        }
        public void BuildProcessImplementationElement(AddIn.EA.Architecture.ComponentLogic.ElementModel.Package viewModel, AddIn.EA.Framework.RepositoryManager templateRepository, BusinessEntityStandardProject itemEntity)
        {
            AddIn.EA.Framework.Package templatePackage = templateRepository.GetPackageByName("Process").GetPackageByName("Server").GetPackageByName("ProcessImplementation");
            AddIn.EA.Framework.Element templateProcessImplementationElement = templatePackage.GetElementByName("[entity_name]");

            //Setup the Client package
            ComponentLogic.ElementModel.Package processPackage = GetViewModelPackage("Process", viewModel, true);
            ComponentLogic.ElementModel.Package serverPackage = GetViewModelPackage("Server", processPackage, true);
            ComponentLogic.ElementModel.Package processImplementationPackage = GetViewModelPackage("ProcessImplementation", serverPackage, true);

            String elementName = templateProcessImplementationElement.Name.Replace("[entity_name]", itemEntity.Name);

            //Prevent existing item before include
            processImplementationPackage.Elements.RemoveAll(it => it.Name.CompareTo(elementName) == 0);

            //Build Client attributes.
            Element ProcessImplementationElement = BuildEntityElementFromTemplate(itemEntity, templateProcessImplementationElement, elementName);

            //Add the methods defined for this layer.
            BindElementMethods(ProcessImplementationElement, itemEntity, "ProcessEntity", "ProcessEntity");

            processImplementationPackage.Elements.Add(ProcessImplementationElement);
        }
        public override void Validate()
        {
        }
    }
}
